<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv=X-UA-Compatible content="IE=edge,chrome=1">
    <meta content=always name=referrer>
    <link rel="stylesheet" type="text/css" href="__STATIC__/css/base_user.css">
    <script src="__STATIC__/js/jquery-1.8.2.js"></script>
    <title>商品列表--筛选</title>
</head>
<body>
<div class="wrap-sp">
    <div class="header">
        <img src="__STATIC__/img/back.png" class="back" onclick=window.location.href="{:url('mobile/user_category/search')}">
        <div style="width: 80%;">
            <input type="search" placeholder="请输入搜索关键字"  id="search" value="{:input('search','')}">
            <img src="__STATIC__/img_user/fl-sousuotubiao.png" onclick="search()">
        </div>
    </div>
    <div class="category">
        <ul>
            <li ><div><a href="javascript:jump(0);"><span>综合</span></a></div></li>
            <li ><div><a href="javascript:jump(1);"><span>销量</span></a></div></li>
            <li ><div><a href="javascript:jump(2);"><span>价格</span><img src="__STATIC__/img_user/fl-shangxia.png" /></a></div></li>
            <li class="cur"><div><a href="{:url('mobile/user_category/goods_shai')}"><span>筛选</span></a></div></li>
        </ul>
        <div class="price">
            <span>价格区间(元)</span>
            <div>
                <input type="number" placeholder="最低价" id="low"><span>─</span>
                <input type="number" placeholder="最高价" id="high">
            </div>
        </div>
    </div>
    <div class="footer">
        <input type="reset" onclick="reset()" value="重置">
        <input type="submit" onclick="confirm()" value="确认">
    </div>
</div>
<script src="__STATIC__/js/layer_mobile/layer.js"></script>
<script>
    $(window).resize(function(){
        $('.footer').toggle();
    });
    $(function (){
        sessionStorage.removeItem('goods_shai_url');
        var low = sessionStorage.getItem('LOW');
        var high = sessionStorage.getItem('HIGH');
        if (low){
            $('#low').val(low);
        }
        if (high){
            $('#high').val(high);
        }
    });
    function jump(type) {
        var search = $('#search').val();
        window.location.href = "{:url('mobile/user_category/search_goods')}?type="+type+"&search="+search;
    }
    //关键词搜索
    function search(){
        var type = 0,
            search = $('#search').val();
        window.location.href = "{:url('mobile/user_category/search_goods')}?type="+type+"&search="+search;
    }
    //取消品牌或者分类
    function del_choose(type){
        //存储高低价
        store_price();
        var now_url = window.location.href;
        var url_arr = now_url.split('&');
        var text = 'brand_id';
        if (type == 2){  //取消分类
            text = "cate_id";
        }
        for (var i=0;i<url_arr.length;i++){
            if (url_arr[i].indexOf(text) == 0){
                delete url_arr[i];
            }else if(url_arr[i].indexOf(text) > 0){
                url_arr[i] = url_arr[i].substr(0,url_arr[i].indexOf(text));
            }
        }
        if (url_arr.length > 1){
            now_url = url_arr.join('&')
        }else{
            now_url = url_arr[0];
        }
        window.location.href = now_url;
    }
    //跳转到品牌
    function jump_brand(){
        //存储高低价
        store_price();
        sessionStorage.setItem('goods_shai_url',window.location.href);
        window.location.href = "{:url('mobile/user_action/brand_list')}";
    }
    //跳转到分类
    function jump_cate_list(){
        //存储高低价
        store_price();
        sessionStorage.setItem('goods_shai_url',window.location.href);
        window.location.href = "{:url('mobile/user_category/index')}?cate_id=recommend";
    }
    //存储高低价
    function store_price(){
        sessionStorage.setItem('LOW',$('#low').val());
        sessionStorage.setItem('HIGH',$('#high').val());
    }
    //重置
    function reset(){
        var storage = sessionStorage;
        storage.removeItem('LOW');
        storage.removeItem('HIGH');
        window.location.href = window.location.href.substr(0,window.location.href.indexOf('?'));
    }
    //确认
    function confirm(){

        var low = $('#low').val(),
            high = $('#high').val(),
            brand_id = "{:input('brand_id','')}",
            cate_id = "{:input('cate_id','')}";
            search = $('#search').val();
        if (low != '' && high == ''){
            layer.open({content:'请填写价格',skin:'msg',time:2});
            return;
        }
        if (low == '' && high != ''){
            layer.open({content:'请填写价格',skin:'msg',time:2});
            return;
        }
        if (parseInt(low) > parseInt(high)){
            layer.open({content:'价格顺序有误',skin:'msg',time:2});
            return;
        }
        sessionStorage.removeItem('LOW');
        sessionStorage.removeItem('HIGH');
        window.location.href = "{:url('mobile/user_category/search_goods')}?price="+low+"-"+high+"&brand_id="+brand_id+"&cate_id="+cate_id+"&search="+search;
    }
</script>
</body>
</html>